package leetcode.easy.limit50;

import java.util.Arrays;

/**
 * @author liuyy
 * @className No27
 * @description 移除元素
 * @date 2019/10/30 17:15
 **/
public class No27 {
    public static void main(String[] args) {
        No27 no27 = new No27();
        int[] nums = new int[]{3, 2, 2, 3};
        int element = no27.removeElement(nums, 2);

        System.out.println(element);
        System.out.println(Arrays.toString(nums));
    }

    public int removeElement(int[] nums, int val) {
        int fast = 0;
        int size = 0;
        while (fast < nums.length) {
            if (nums[fast] != val) {
                nums[size] = nums[fast];
                size++;
            }
            fast++;
        }
        return size;
    }
}
